package com.shinewind.info.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shinewind.info.mapper.IModelCommentMapper;
import com.shinewind.info.service.IModelCommentService;
import com.shinewind.info.service.IModelInfoService;
import com.shinewind.pojo.dto.PageDto;
import com.shinewind.pojo.entity.Comment;
import com.shinewind.pojo.entity.ModelComment;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@DubboService
public class ModelCommentServiceImpl extends ServiceImpl<IModelCommentMapper, ModelComment> implements IModelCommentService {
    @Autowired
    private IModelInfoService iModelInfoService;

    @Override
    public List<ModelComment> getModelCommentsByPageANDId(String dId, PageDto pageDto) {
        List<ModelComment> comments = this.lambdaQuery().eq(ModelComment::getDId,dId).orderByDesc(ModelComment::getPublishTime)
                                     .page(new Page<>(pageDto.getCurrentPage(), pageDto.getPageSize())).getRecords();
        return comments;
    }

    @Override
    public Integer getTotalByDid(String dId) {
        Integer total = Math.toIntExact(this.lambdaQuery().eq(ModelComment::getDId, dId).count());
        return total;
    }

    @Override
    public Boolean deleteCommentBycId(String cId) {
        //根据cId删除评论
        return this.lambdaUpdate().eq(ModelComment::getCId,cId).remove();
    }

    @Override
    public Boolean deleteCommentByDto(ModelComment modelComment) {
        return this.lambdaUpdate().eq(ModelComment::getDId,modelComment.getDId())
                .eq(ModelComment::getCId,modelComment.getCId())
                .remove();
    }
}
